<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="{{url_for('static',filename='js/jquery.min.js')}}"></script>
    <script src="{{url_for('static',filename='js/jquery.dataTables.min.js')}}"></script>
    <link rel="stylesheet" href="{{url_for('static',filename='css/jquery.dataTables.min.css')}}">
    <link rel="stylesheet" href="{{url_for('static',filename='css/bootstrap.min.css')}}">
    <link rel="stylesheet" href="{{url_for('static',filename='css/bootstrap-select.min.css')}}">
    <title>盘中出手</title>
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
    <div class="container-fluid">
    <div class="navbar-header">
        <a class="navbar-brand" href="#">盯盘宝后台管理系统</a>
    </div>
    <div>
        <ul class="nav navbar-nav">
            <li ><a href="{{ url_for('start_web') }}">首页</a></li>
            <li ><a href="{{ url_for('permission_manage') }}">权限配置</a></li>
        </ul>
        <ul class="nav navbar-nav navbar-right">
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                    管理员{{ session['admin'] if session['admin'] else "未登录" }}
                    <b class="caret"></b>
                </a>
                <ul class="dropdown-menu">
                    <li><a href="{{ url_for("login_out") }}">退出</a></li>
                </ul>
            </li>
        </ul>
    </div>
    </div>
</nav>
<div>
    <h3 align="center">盘中出手</h3>
    <br/>
    <div style="border:1px solid rgb(68, 113, 188);">
    <div id="select_all" align="center">

    是否未开板的新股:<select id="lxzt">
        <option value="全部">全部</option>
        <option value="是">是</option>
        <option value="否">否</option>
        </select>

    所属概念排名:<select  id="order" class="selectpicker" multiple>

                </select>

    是否涨停价开盘:<select id="is_yzb">
        <option value="全部">全部</option>
        <option value="是">是</option>
        <option value="否">否</option>
        </select>
    封板资金:<select id="lzt_capital">
                    <option value="全部">全部</option>
                    <option value="小于阈值">小于阈值</option>
                    <option value="大于阈值">大于阈值</option>
                    </select>
    是否高位板:<select id="gaowei">
        <option value="全部">全部</option>
        <option value="是">是</option>
        <option value="否">否</option>
        </select>
    放量阴线10个交易日内:<select id="big_vol_shade_line">
        <option value="全部">全部</option>
        <option value="无">无</option>
        <option value="现象1">现象1</option>
        <option value="现象2">现象2</option>
        </select>
    是否有压力位:<select id="resistance_section">
        <option value="全部">全部</option>
        <option value="无">无</option>
        <option value="有">有</option>
        </select>
    是否买入:<select id="is_buy">
        <option value="全部">全部</option>
        <option value="已买入">已买入</option>
        <option value="未买入">未买入</option>
        </select>
    </div>
    <br/>
    <div align="center">
        <div class="btn-group btn-group-lg" role="group" aria-label="...">
        <div class="btn-group" role="group" align="center">
        <button type="button" class="btn btn-primary" onclick="refreshConditionFilterData('condition')">查询</button>
        </div>
        <div class="btn-group" role="group" align="center">
        <button type="button" class="btn btn-primary" onclick="clearCondition()">清空条件</button>
        </div>
        </div>
    </div>
    </div>
    <br/>
    <br/>
    <div class="row" align="center" style="border:1px solid rgb(68, 113, 188);">
    <div id ="stock_checkbox"  style="width:80%;">

    </div>
        <br/>
    <div align="center">
        <div class="btn-group btn-group-lg" role="group" aria-label="...">
        <div class="btn-group" role="group" align="center">
        <button type="button" class="btn btn-primary" onclick="refreshConditionFilterData('stock')">查询</button>
        </div>
        <div class="btn-group" role="group" align="center">
        <button type="button" class="btn btn-primary" onclick="allIn(true)">全选</button>
        </div>
        <div class="btn-group" role="group" align="center">
        <button type="button" class="btn btn-primary" onclick="allIn(false)">全不选</button>
        </div>
        </div>
    </div>
        <br/>
    </div>
    <br/>
    <br/>
    <div align="center">
        <p style="font-size:22px;color:rgb(68,113,188)">程序执行顺序<span class="glyphicon glyphicon-arrow-right"></span></p>
    </div>
    <table id="robot2_panzhong" border="1" class="display" style="width:100%">
        <thead>
        <tr>
            <th rowspan="2">股票</th>
            <th rowspan="2">涨停时间</th>
            <th rowspan="2">是否未开板新股</th>
            <th rowspan="2">选股报前瞻概念</th>
            <th rowspan="2">所属概念排名</th>
            <th rowspan="2">是否涨停价开盘</th>
            <th rowspan="2">是否在黑名单</th>
            <th rowspan="2">热点板块</th>
            <th colspan="2">封板资金(大于默认封板资金且大于标杆资金)</th>
            <th rowspan="2">30分钟量比(阈值10)</th>
            <th rowspan="2">是否妖股反弹</th>
            <th colspan="5">个股属性(新股不限涨停\高开)</th>
            <th rowspan="2">是否高位板(近三天2次及以上涨停)</th>
            <th rowspan="2">放量阴线10个交易日内</th>
            <th rowspan="2">是否有压力位</th>
            <th rowspan="2">同一板块限制(小于3)</th>
            <th rowspan="2">是否买入</th>
            <th rowspan="2">程序过滤原因</th>
        </tr>
        <tr>
            <th>默认封板资金(阈值300万)</th>
            <th>标杆资金(万)</th>
            <th>一年内高开率(阈值0.39,9点50前不限)</th>
            <th>炸板率(阈值0.41)</th>
            <th>涨停数(阈值1)</th>
            <th>最近连板数(阈值2)</th>
            <th>是否新股(60天内上市)</th>
        </tr>
        </thead>
    </table>
    <br/>
    <br/>
</div>



<script type="text/javascript">

var result = {{ result|tojson}};
var obj = JSON.parse(result);
var concept_list = obj.concept_list;
var htmlStr = '<option value="全部" selected>全部</option>';
for (var i=0;i<concept_list.length;i++){
    htmlStr += '<option value="'+concept_list[i]+'">'+concept_list[i]+'</option>';
}
$("#order").html(htmlStr);


var name_list = obj.name_list;
var htmlStr = "";
for (var i=0;i<name_list.length;i++){
    htmlStr +=
    "<label class=\"checkbox-inline\">" +
    "<input class=\"stock-checkbox\" type=\"checkbox\" id=\"inlineCheckbox1\" value=\"" + name_list[i] +
    "\">" + name_list[i] +
    "</label>";
}
$("#stock_checkbox").html(htmlStr);

function allIn(flag){
    if (flag){
          $(".stock-checkbox").each(function (key,value) {
        $(value).prop("checked",true);
        var value = $(value).val();
        console.log(value);
        });
    }else{
        $(".stock-checkbox").each(function (key,value) {
        $(value).prop("checked",false);
        var value = $(value).val();
        console.log(value);
        });
    }
}
function clearCondition(){
    $('#lxzt').val('全部');
    $('#order').val('全部');
    $(".filter-option-inner-inner").html("全部");
    $('#is_yzb').val('全部');
    $('#lzt_capital').val('全部');
    $('#gaowei').val('全部');
    $('#big_vol_shade_line').val('全部');
    $('#resistance_section').val('全部');
    $('#is_buy').val('全部');
}
function getCondition(inputList){
    var chooses=[];
    var lxzt = $('#lxzt').val();
    var each_dict={};
    each_dict['type']='lxzt';
    each_dict['value'] = lxzt;
    if (lxzt!='全部'){
        chooses.push(each_dict);
    }

    var order = $('#order').val();
    var each_dict={};
    each_dict['type']='order';
    each_dict['value'] = order;
    if (order.indexOf('全部')==-1 & order.length>0){
        chooses.push(each_dict);
    }

    var is_yzb = $('#is_yzb').val();
    var each_dict={};
    each_dict['type']='is_yzb';
    each_dict['value'] = is_yzb;
    if (is_yzb!='全部'){
        chooses.push(each_dict);
    }

    var lzt_capital = $('#lzt_capital').val();
    var each_dict={};
    each_dict['type'] = 'lzt_capital';
    each_dict['value'] = lzt_capital;
    if (lzt_capital!='全部'){
        chooses.push(each_dict);
    }

    var gaowei=$('#gaowei').val();
    var each_dict={};
    each_dict['type']='gaowei';
    each_dict['value'] = gaowei;
    if (gaowei!='全部'){
        chooses.push(each_dict);
    }

    var big_vol_shade_line=$('#big_vol_shade_line').val();
    var each_dict={};
    each_dict['type'] = 'big_vol_shade_line';
    each_dict['value'] = big_vol_shade_line;
    if (big_vol_shade_line!='全部'){
        chooses.push(each_dict);
    }

    var resistance_section=$('#resistance_section').val();
    var each_dict={};
    each_dict['type'] = 'resistance_section';
    each_dict['value'] = resistance_section;
    if (resistance_section!='全部'){
        chooses.push(each_dict);
    }

    var is_buy= $('#is_buy').val();
    var each_dict={};
    each_dict['type'] = 'is_buy';
    each_dict['value'] = is_buy;
    if (is_buy!='全部'){
        chooses.push(each_dict);
    }

    var outputList=choosesFilter(inputList,chooses);
    return outputList;
}

function getSelectStock(inputList) {
    var stockList = [];
    $(".stock-checkbox").each(function (key,value) {
        if ($(value).is(':checked')){
            var value = $(value).val();
            stockList.push(value);
        }
    });
    var outputList=inputList.filter(
        function (item) {
            return (stockList.indexOf(item["name"]) > -1);
        });
    return outputList;
}
function choosesFilter(inputList,chooses){
    let tmpList=[];
    if(chooses.length==0){
        tmpList=inputList;
        return tmpList;
    }else{
        for (let choice of chooses){
            tmpList=inputList.filter(
                function (item) {
                    if (jQuery.type(choice.value) == "array"){
                        var flag = false;
                        for (var i=0;i<choice.value.length;i++){
                            if (jQuery.type(item[choice.type])=="string"){
                                if (item[choice.type].indexOf(choice.value[i]) > -1){
                                    flag = true;
                                }
                            }
                        }
                        return flag;
                    }
                    else if (jQuery.type(item[choice.type])=="string"){
                        return item[choice.type].indexOf(choice.value) > -1;
                    }
                }
                );
            inputList=tmpList;
        }
        return tmpList;
    }
}

function reloadData(dataList) { //dataArr是表格数据数组，和初始化配置需一样的结构
    var table = $('#robot2_panzhong').dataTable();
    var oSettings = table.fnSettings(); //这里获取表格的配置
    table.fnClearTable(this); //动态刷新关键部分语句，先清空数据
    for (var i = 0, l = dataList.length; i < l; i++) {
        table.oApi._fnAddData(oSettings, dataList[i]); //这里添加一行数据
    }
    oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
    table.fnDraw();//绘制表格
}
{#function reloadData(dataList) {#}
{#        var realTable=null;#}
{#        realTable = $('#robot2_panzhong').DataTable();#}
{#        var currentPage = realTable.page();#}
{#        realTable.clear();#}
{#        realTable.rows.add(dataList);#}
{#        realTable.page(currentPage).draw( false );#}
{#    }#}

function refreshConditionFilterData(type){
                $.ajax({
                url: '/robotPanZhongData',
                async:true,
                success:function(result){
                    var obj=JSON.parse(result);
                    var condition_filter_list = obj.result_list;
                    if (type == 'condition'){
                        allIn(true);
                        var condition_filter_list_result = getCondition(condition_filter_list);
                    }else{
                        clearCondition();
                        var condition_filter_list_result = getSelectStock(condition_filter_list);
                    }
                    reloadData(condition_filter_list_result);
                }
            }
        );

    }


$('#robot2_panzhong').DataTable( {
    "paging":false,
"ordering": false,
"info":false,
"data": obj.result_list,
"columns": [
      { "data": "name" ,sDefaultContent:"数据异常"},
      { "data": "zt_time",sDefaultContent:"数据异常" },
      { "data": "lxzt",sDefaultContent:"数据异常" },
     { "data": "concept",sDefaultContent:"数据异常" },
      { "data": "order",sDefaultContent:"数据异常" },
      {"data":"is_yzb",sDefaultContent:"数据异常"},
      { "data": "is_black",sDefaultContent:"数据异常" },
      {"data":"is_hot",sDefaultContent:"数据异常"},
      { "data": "lzt_capital",sDefaultContent:"数据异常" },
      {"data":"bgzj",sDefaultContent:"数据异常"},
      { "data": "volume_ratio",sDefaultContent:"数据异常" },
      {"data":"is_special",sDefaultContent:"数据异常"},
      { "data": "gk_rate",sDefaultContent:"数据异常" },
      { "data": "zb_rate",sDefaultContent:"数据异常" },
      { "data": "zt_num",sDefaultContent:"数据异常" },
      { "data": "last_lianban",sDefaultContent:"数据异常" },
      {"data":"is_new_market",sDefaultContent:"数据异常"},
      {"data":"gaowei",sDefaultContent:"数据异常"},
      {"data":"big_vol_shade_line",sDefaultContent:"数据异常"},
      {"data":"resistance_section",sDefaultContent:"数据异常"},
      {"data":"limit_in_same_block",sDefaultContent:"数据异常"},
      { "data": "is_buy",sDefaultContent:"数据异常" },
      {"data":"reason",sDefaultContent:"数据异常"}
]});
allIn(true);

{#refreshConditionFilterData("condition");#}

</script>
<script src="{{url_for('static',filename='js/bootstrap.min.js')}}"></script>
<script src="{{url_for('static',filename='js/bootstrap-select.min.js')}}"></script>
<script src="{{url_for('static',filename='js/defaults-zh_CN.js')}}"></script>
</body>
</html>

